#include <iostream>
#include <algorithm>

using namespace std;

const int T = 1010;

int N, M;
int volumes[T], prices[T];
int dp[T][T];

int main()
{
    cin >> N >> M;
    for (int i = 1; i <= N; i++)
        cin >> volumes[i] >> prices[i];

    for (int i = 1; i <= N; i++)
        for (int j = 0; j <= M; j++)
        {
            // 取上一层最优状态
            dp[i][j] = dp[i - 1][j];
            // 如果能存下
            if (j >= volumes[i])
                // 每次j循环，与加第i个物品作比较，保留总价高的方案
                dp[i][j] = max(dp[i][j], dp[i][j - volumes[i]] + prices[i]);
        }

    cout << dp[N][M] << endl;
    return 0;
}
